package com.css.fxfzmh.modules.util.controller;

import com.alibaba.fastjson.JSON;
import com.css.fxfzmh.base.response.RestResponse;
import com.css.fxfzmh.logInfo.SysLog;
import com.css.fxfzmh.web.PlatformSessionContext;
import com.css.fxfzmh.zcpt.sys.entity.OrgRoleExt;
import com.css.fxfzmh.zcpt.sys.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @Author: zhangSongRui
 * @CreateTime: 2023/05/11
 * @Description: 获取用户权限congtoller
 */
@RestController
@Slf4j
@RequestMapping("/authority")
public class AuthorityController {
    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 获取用户权限
     */
    @SysLog("获取用户权限")
    @GetMapping("/getRoleByUserId")
    public RestResponse getRoleByUserId() {
        RestResponse restResponse = null;
        try {
            String jsonStr = sysRoleService.getRoleByUserId(PlatformSessionContext.getUserID());
//            List<OrgRoleExt> parse = JSON.parseArray(jsonStr,OrgRoleExt.class);
            if(jsonStr.contains("gzmh_admin_role")){
                restResponse = RestResponse.succeed(true);
            }else {
                restResponse = RestResponse.succeed(false);
            }
        } catch (Exception e) {
            log.error("查询角色失败!", e);
            restResponse = RestResponse.fail("查询角色失败!");
        }
        return restResponse;
    }
}
